Skip to content

Conversation

@ssd04
Copy link
Contributor

@ssd04 ssd04 commented Mar 9, 2023

No description provided.

@ssd04 ssd04 self-assigned this Mar 9, 2023
Base automatically changed from mongo-db-client to feat/mongo-db-integration March 13, 2023 09:47
@ssd04 ssd04 marked this pull request as ready for review March 14, 2023 16:26
IsInterfaceNil() bool
}

type StorageWithIndexChecker interface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

// ShardedStorageFactory defines the methods available for a sharded storage factory
type ShardedStorageFactory interface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps this interface should be renamed as well to StorageWithIndexFactory or similar

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return handler.bucket.Has(key)
}

func (handler *bucketIndexHandler) UpdateWithCheck(key []byte, fn func(data interface{}) (interface{}, error)) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing comment

also, this should be protected by a mutex(which should be different than the current mut which is used for last index key), as another Put may happen right between Get and Put..and reuse the mutex on Put/Get

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we would be able to use the new keymutex defined in the other PR, to get a critical section per same key.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

mut sync.RWMutex
}

// NewMongoDBIndexHandler returns a new instance of a bucket index handler
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// NewMongoDBIndexHandler returns a new instance of a bucket index handler
// NewMongoDBIndexHandler returns a new instance of a mongo db index handler

return bucket.Has(key)
}

func (sswi *shardedStorageWithIndex) UpdateWithCheck(key []byte, fn func(data interface{}) (interface{}, error)) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing comment

)

const (
connectTimeoutSec = 60
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we consider moving these constants to MongoDBConfig ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

return nil
PutCalled func(coll mongodb.CollectionID, key []byte, data []byte) error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file name should be renamed as well

return uint32(len(mock.cache)), nil
}

func (mock *shardedStorageWithIndexMock) UpdateWithCheck(key []byte, fn func(data interface{}) (interface{}, error)) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing comment

Close() error
AllocateBucketIndex() (uint32, error)
GetLastIndex() (uint32, error)
UpdateWithCheck(key []byte, fn func(data interface{}) (interface{}, error)) error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps rename this interface to IndexHandler, as now it is implemented by mongodbIndexHandler as well

}

err = handler.saveNewIndex(0)
err = saveNewIndex(handler.bucket, 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this changed to give the bucket as parameter instead of having saveNewIndex as method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i changed to be able to use saveNewIndex also in mongoIndexHandler

}

// ShardedStorageFactory defines the methods available for a sharded storage factory
type ShardedStorageFactory interface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return handler.bucket.Has(key)
}

func (handler *bucketIndexHandler) UpdateWithCheck(key []byte, fn func(data interface{}) (interface{}, error)) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we would be able to use the new keymutex defined in the other PR, to get a critical section per same key.

filter := bson.D{{Key: "_id", Value: string(key)}}

entry := &mongoEntry{}
err := coll.FindOne(sessCtx, filter).Decode(entry)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i did not use it initially since we store counter as byte array and we need to split the operation to do the conversions

return nil, err
}

bucketIndexHandlers := make(map[uint32]core.BucketIndexHandler, 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need the len

return nil, err
}

bucketIDProvider, err := bucket.NewBucketIDProvider(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave a todo to refactor the bucket usage with mongo, I think we can do without it as we anyway don't have direct control on the shards

return handler, nil
}

err = saveNewIndex(handler.storer, initialIndexValue)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not safe if we configure multiple MFA instances
it should be through a transaction instead, like allocate Index.

also since we always write at the same key, this can be a bottleneck (will not be more performant no matter how many shards are configured as the same key will always be allocated to a single shard). - maybe add a todo here to see how we can improve.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there is no provided way from Mongo, maybe we can use the same bucket mechanism we have with localDB? (it would require that we can specify the shard in which we write/ from which we read)

@ssd04 ssd04 marked this pull request as draft April 4, 2023 13:21
@ssd04 ssd04 changed the base branch from feat/mongo-db-integration to feat/mongo-db-concurrency April 13, 2023 08:25
@ssd04
Copy link
Contributor Author

ssd04 commented Oct 12, 2023

Blocked for now, currently it is not a priority. It has to be refactored to use mongodb transactions in a cleaner way in service resolver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants